<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 寄生继承
        function inherit(parent,child){
            // 窃取父类的原型
            // 根据原型对象创建一个新的对象
            var parentProto=Object.create(parent.prototype);
            // 把父类的constructor指向自己
            parentProto.constructor=child;
            // 让自己的原型指向父类的继承
            child.prototype=parentProto;
        }

        function Person(name,age,sex){
            this.named=name;
            this.age=age;
            this.sex=sex;
        }
        Person.prototype={
            // 特殊的属性,原型对象的指针指向构造函数(系统内置)
            constructor:Person,
            run(){
                console.log("父类的run");
            },
            eat(){
                console.log("父类的吃");
            }
        }

        function Student(num,name,age,sex){
            Person.call(this,name,age,sex);
            this.num=num;
        }

        inherit(Person,Student)

        var stu=new Student(12,"阿发",21,"男");
        console.log(stu);
    </script>
</body>
</html>